package com.hzyl.famousreader.repository.persistence;

import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.TypeConverters;
import com.blankj.utilcode.util.Utils;
import com.hzyl.famousreader.repository.persistence.dao.AdDao;
import com.hzyl.famousreader.repository.persistence.dao.BookDao;
import com.hzyl.famousreader.repository.persistence.entity.Ad;
import com.hzyl.famousreader.repository.persistence.entity.Book;
import com.hzyl.famousreader.repository.persistence.entity.BookChapter;

import static com.hzyl.famousreader.repository.persistence.AppDataBase.DATABASE_VERSION;

@Database(version = DATABASE_VERSION,
  entities = {Book.class, Ad.class, BookChapter.class},
  exportSchema = false)
@TypeConverters({Converters.class})
public abstract class AppDataBase extends RoomDatabase {

  public static final String DATABASE_NAME = "famous_reader";
  public static final int DATABASE_VERSION = 1;

  private static AppDataBase INSTANCE;

  public static AppDataBase getInstance() {
    if (INSTANCE == null) {
      synchronized (AppDataBase.class) {
        if (INSTANCE == null) {
          INSTANCE = Room.databaseBuilder(Utils.getApp(), AppDataBase.class, DATABASE_NAME).build();
        }
      }
    }
    return INSTANCE;
  }

  /**
   * 书籍
   * @return
   */
  public abstract BookDao bookDao();

  /**
   * 广告
   * @return
   */
  public abstract AdDao adDao();
}
